<template>
  <div>
    <VolBox :lazy="true" :model.sync="modelRZ" title="入账" :width="800" :height="500">
      <Button type="success" @click="addYJ" class="bot10">新增</Button>
      <Button type="success" @click="editYJ" class="bot10">编辑</Button>
      <el-table :data="orderTableData" style="width: 100%;" row-key="id" border ref="orderTableData"
        :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        @selection-change="handleSelectionChange" :expand-row-keys="expanRows"
        @expand-change="handleExpandChange">
        <el-table-column type="selection" width="55" :selectable="checkboxSelect">
        </el-table-column>
        <el-table-column type="expand">
          <template slot-scope="scope">
            <vol-table ref="RZoctable" :loadKey="true" :columns="columnsRZ"
              :tableData="goodListInfo" :height="250" :summary="true" :columnIndex="true"
              :click-edit="true" :ck="false"></vol-table>
          </template>
        </el-table-column>
        <el-table-column prop="outTradeNo" label="订单号" width="180">
        </el-table-column>
        <el-table-column prop="totalPrice" label="总金额" width="100">
        </el-table-column>
        <el-table-column prop="isPay" label="支付状态">
          <template slot-scope="scope">
            {{  scope.row.isPay == 0 ? '未支付' : scope.row.isPay == 1 ? '已支付' : '支付失败'}}
          </template>
        </el-table-column>
        <el-table-column prop="payDesc" label="操作">
          <template slot-scope="scope">
            <el-button type="text" size="mini" @click="payClick(scope.row)"
              :disabled="scope.row.isPay == 1 ? true: false">支付</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer">
        <Button type="default" @click="modelRZ = false">关闭</Button>
      </div>
    </VolBox>

    <VolBox :lazy="true" :model.sync="modelAddJZ" :title="goodTitle" :width="600" :height="300">
      <el-table :data="goodTableData" border>
        <el-table-column label="商品">
          <template slot-scope="scope">
            <div class="goods">
              <el-select v-model="scope.row.goodId" placeholder="请选择" size="small"
                @change="setShop(scope.row)">
                <el-option v-for="item in goodList" :key="item.id" :label="item.name"
                  :value="item.id">
                </el-option>
              </el-select>
              <div class="goodsr">
                <a @click="addGoods(scope.row)">添加商品</a> |
                <a @click="delGoods(scope.row)">删除</a>
              </div>
            </div>

          </template>
        </el-table-column>
        <el-table-column label="数量" width="170">
          <template slot-scope="scope">
            <el-input-number v-model="scope.row.goodNum" size="small" :min="1"
              @change="setGoodsNum(scope.row)"></el-input-number>
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer">
        <Button type="success" @click="submitAddGoods">确认</Button>
        <Button type="default" @click="modelAddJZ = false">关闭</Button>
      </div>
    </VolBox>
    <VolBox :lazy="true" :model.sync="modelYJ" title="押金" :width="400">
      <VolForm ref="formRulesYJ" :label-width="100" :formFields="formFieldsYJ"
        :formRules="formRulesYJ">
      </VolForm>
      <div slot="footer">
        <Button type="default" @click="modelYJ = false">关闭</Button>
      </div>
    </VolBox>
    <VolBox :lazy="true" :model.sync="modelBG" title="变更" :width="300">
      <VolForm ref="formRulBG" :label-width="80" :formFields="formFieldsBG"
        :formRules="formRulesBG">
      </VolForm>
      <div slot="footer">
        <Button type="success" @click="submitBG">确认</Button>
        <Button type="default" @click="modelBG = false">关闭</Button>
      </div>
    </VolBox>
    <VolBox :lazy="true" :model.sync="modelJZ" title="结账" :width="800" :height="500">
      <el-table :data="goodsOrderTableData" style="width: 100%;" row-key="id" border
        ref="orderTableData" :tree-props="{children: 'children', hasChildren: 'hasChildren'}"
        :expand-row-keys="expandRows" @expand-change="handleExpandChange2">
        <el-table-column type="expand">
          <template slot-scope="scope">
            <vol-table ref="JZoctable" :loadKey="true" :columns="columnsJZ"
              :tableData="goodListInfo" :height="250" :summary="true" :columnIndex="true"
              :click-edit="true" :ck="false"></vol-table>
          </template>
        </el-table-column>
        <el-table-column prop="outTradeNo" label="订单号" width="180">
        </el-table-column>
        <el-table-column prop="totalPrice" label="总金额" width="100">
        </el-table-column>
        <el-table-column prop="isPay" label="支付状态">
          <template slot-scope="scope">
            {{  scope.row.isPay == 0 ? '未支付' : scope.row.isPay == 1 ? '已支付' : '支付失败'}}
          </template>
        </el-table-column>
      </el-table>
      <div slot="footer">
        <Button type="success" @click="submitJZ">结账</Button>
        <Button type="default" @click="modelJZ = false">关闭</Button>
      </div>
    </VolBox>

    <VolBox :lazy="true" :model.sync="modelZK" title="折扣" :width="500">
      <VolForm ref="formRuleZK" :label-width="100" :formFields="formFieldsZK"
        :formRules="formRuleZK">
      </VolForm>
      <div slot="footer">
        <Button type="success" @click="submitZK">确认</Button>
        <Button type="default" @click="modelZK = false">关闭</Button>
      </div>
    </VolBox>
    <div id='printDetail' style="height: 1px;  position: absolute; ">
      <div>
        <h3>【 {{ printInforma.danwei}} 】</h3>
        <div>收银员：{{ printInforma.syyUserNmae }} </div>
        <div>时间：{{printInforma.time}}</div>
      </div>
      <div class="tablef">
        <h3 class="bor">房号：{{printInforma.room}}</h3>
        <div>
          <div class="top">
            <span class="w100">名称</span>
            <span class="w50">单价</span>
            <span class="w50">押金</span>
            <span class="w50">数量</span>
          </div>
          <div class="tac" v-for="(i,ii) in tablDataDY" :key="ii">
            <span class="w100">{{ i.goodName}}</span>
            <span class="w50">{{ i.originalPrice}}</span>
            <span class="w50">{{ i.paydepositPrice}}</span>
            <span class="w50">{{ i.stock}}</span>
          </div>
        </div>
      </div>
      <div class="zfnr bor">
        <div>消费：{{(printInforma.totalprice).toFixed(2)}}</div>
        <div v-show="printInforma.predfer">优惠：{{printInforma.preferential}}</div>
        <div>押金：{{(printInforma.deposit).toFixed(2)}}</div>
        <div v-show="printInforma.deductiondepositprice != 0">
          押金扣除：{{(printInforma.deductiondepositprice).toFixed(2)}}</div>
        <div>实退：{{(printInforma.Actualwithdrawal).toFixed(2)}}</div>
        <div class="payStatus bor">
          <div class="one">支付方式</div>
          <div class="tw">
            <div>
              <span class="zj">{{printInforma.payType}}：</span>
              {{(printInforma.payTypePay).toFixed(2)}}
            </div>
            <div>
              <span class="zj">官网支付：</span>
              {{(printInforma.officialwebsite).toFixed(2)}}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import VolBox from "@/components/basic/VolBox.vue";
import VolForm from "@/components/basic/VolForm.vue";
import VolTable from "@/components/basic/VolTable.vue";
import printJS from "print-js";
export default {
  name: "CampsiteLeaseBox",
  components: {
    VolBox,
    VolForm,
    VolTable,
  },
  data() {
    return {
      printInforma: {
        danwei: "",
        time: "",
        room: "",
        predfer: true,
        deption: true,
        totalprice: 0,
        preferential: 0,
        deposit: 0,
        deductiondepositprice: 0,
        Actualwithdrawal: 0,
        WeChat: 0,
        officialwebsite: 0,
        payTypePay: 0,
        payType: "",
      },
      modelDY: false,
      modelBG: false,
      formFieldsBG: {
        id: "",
        chid: "",
      },
      formRulesBG: [
        [
          {
            title: "营房",
            field: "chid",
            type: "select",
            dataKey: "",
            data: [],
            required: true,
            onChange: (n) => {
              this.formFieldsBG.id = "";
              let parma = {
                page: 1,
                rows: 30,
                sort: "modifyDate",
                order: "id",
                wheres: `[{\"name\":\"chid\",\"value\":\"${n}\",\"displayType\":\"text\"},{\"name\":\"houseType\",\"value\":\"${this.BGDETAIL.houseType}\",\"displayType\":\"text\"},{\"name\":\"status\",\"value\":\"0\",\"displayType\":\"=\"}]`,
              };
              this.http
                .post("/api/CampsiteLease/getPageData", parma)
                .then((res) => {
                  this.formRulesBG[1][0].data = res.rows.map((i) => {
                    return {
                      key: i.id,
                      value: i.code,
                    };
                  });
                });
            },
          },
        ],
        [
          {
            title: "营位",
            field: "id",
            type: "select",
            dataKey: "",
            data: [],
            required: true,
          },
        ],
      ],
      modelJZ: false,
      modelRZ: false,
      columnsYJ: [
        { field: "outTradeNo", title: "订单号", type: "string" },
        { field: "totalPrice", title: "总金额", type: "string" },
        {
          field: "isPay",
          title: "是否支付",
          type: "select",
          bind: {
            key: "enables",
            data: [],
          },
        },
      ],
      modelAddJZ: false,
      formFieldsAddYJ: {
        shop: [],
      },
      goodList: [],
      columnsRZ: [
        { field: "goodName", title: "商品名称", type: "string" },
        { field: "originalPrice", title: "单价", type: "decimal" },
        { field: "paydepositPrice", title: "押金金额", type: "decimal" },
      ],
      columnsJZ: [
        { field: "goodName", title: "商品名称", type: "string" },
        { field: "originalPrice", title: "单价", type: "decimal" },
        { field: "paydepositPrice", title: "押金金额", type: "decimal" },
        {
          field: "deductionDepositPrice",
          title: "扣款押金",
          type: "text",
          edit: { type: "text", keep: true },
        },
        {
          field: "status",
          title: "操作",
          fixed: "right",
          width: 150,
          render: (h, { row, column, index }) => {
            return h(
              "el-button",
              {
                props: {
                  type: "text",
                  size: "mini",
                },
                on: {
                  click: (e) => {
                    let parma = {
                      mainData: {
                        ...this.tkRow,
                      },
                      detailData: [row],
                      delKeys: null,
                    };
                    this.http
                      .post("/api/CampHouseDeposit/update", parma)
                      .then((res) => {
                        if (res.status) {
                          this.$Message.success(res.message);
                        } else {
                          this.$Message.error(res.message);
                        }
                      });
                  },
                },
              },
              "扣款押金"
            );
          },
        },
      ],
      JZListInfo: [],
      modelYJ: false,
      formFieldsYJ: {
        pay_code: "",
        yj: "",
        authcode: "",
        isPay: 0,
      },
      formRulesYJ: [
        [
          {
            title: "支付方式",
            required: true,
            field: "pay_code",
            type: "select",
            dataKey: "",
            data: [],
          },
        ],
        [
          {
            title: "押金",
            field: "yj",
            type: "text",
            disabled: true,
          },
        ],
        [
          {
            title: "扫码",
            field: "authcode",
            type: "text",
            onKeyPress: ($event) => {
              if ($event.keyCode == 13) {
                this.submitYJ();
              }
            },
          },
        ],
      ],
      RZDETAIL: {},
      orderTableData: [],
      goodListInfo: [],
      expanRows: [],
      expandRows: [],
      orderTime: null,
      repeatPay: 0,
      goodTableData: [],
      goodsOrderTableData: [],
      BGDETAIL: {},
      goodsStatus: false,
      tkRow: {},
      tablDataDY: [],
      isHidden: false,
      isPrint: false,
      goodTitle: "新增商品",
      multipleSelection: [],
      BildGoodList: [],
      modelZK: false,
      formFieldsZK: {
        discount: "",
        discountRemark: "",
        depositDiscount: "",
        depositDiscountRemark: "",
      },
      formRuleZK: [
        [
          {
            title: "商品折扣",
            field: "discount",
            type: "text",
          },
          {
            title: "商品折扣原因",
            field: "discountRemark",
            type: "text",
          },
        ],
        [
          {
            title: "押金折扣",
            field: "depositDiscount",
            type: "text",
          },
          {
            title: "商品折扣原因",
            field: "depositDiscountRemark",
            type: "text",
          },
        ],
      ],
      resultsOutTraeNo: "",
    };
  },
  methods: {
    getFormOptionYJ(field) {
      let option;
      this.formRulesYJ.forEach((x) => {
        x.forEach((item) => {
          if (item.field == field) {
            option = item;
          }
        });
      });
      return option;
    },
    checkboxSelect(e, i) {
      if (e.isHouseDeposit == 0 || e.isPay == 1) {
        return false;
      } else {
        return true;
      }
    },
    delsameObjvalue(arr, resultNum, keyName, keyValue) {
      const warp = new Map();
      arr.forEach((i) => {
        let str = keyName.map((v) => i[v]).join("");
        i[resultNum] = keyValue.reduce((p, c) => (p += i[c]), 0);
        warp.has(str)
          ? (warp.get(str)[resultNum] += i[resultNum])
          : warp.set(str, i);
      });
      return Array.from(warp).map(([, v]) => v);
    },
    billPrintClick(e) {
      let param = {
        orderNumber: e.orderNumber,
      };
      this.http.get("/api/CampHouseOrder/PrintBill", param).then((res) => {
        let data = res.data;
        this.tablDataDY = data.goodList.map((i) => {
          return {
            stock: i.key,
            goodName: i.value.goodName,
            originalPrice: i.value.originalPrice,
            paydepositPrice: i.value.paydepositPrice,
          };
        });
        console.log(this.tablDataDY);
        this.printInforma = {
          danwei: data.unitName,
          time: data.printTime,
          room: data.houseNum,
          syyUserNmae: data.syyUserNmae,
          predfer: false,
          deption: false,
          totalprice: data.xf,
          preferential: 2,
          deposit: data.yj,
          deductiondepositprice: 0,
          Actualwithdrawal: data.st,
          payType: data.payType,
          payTypePay: data.payPrice,
          officialwebsite: data.websitePay,
        };

        this.$nextTick(() => {
          printJS({
            printable: "printDetail", // 标签元素id
            header: null,
            type: "html",
            headerStyle:
              "font-size:6px;font-weight:600;text-align:center;padding:15px 0 10px 0;", //标题设置
            scanStyles: false, //不适用默认样式
            repeatTableHeader: false, //打印json表头只显示在第一页
            style: `@page{size:auto;margin: 0 10mm}
              #printDetail {height: 100px;font-size:6px}#printDetail h3 {margin: 10px 0;}#printDetail .zfnr {text-align: right;margin-top: 20px;}
              #printDetail .zfnr .payStatus {margin-top: 10px;text-align: left;}#printDetail .zfnr .payStatus .tw {text-align: right;}
              #printDetail .zfnr .payStatus .tw .zj {display: inline-block;width: 80px;text-align: right;}
              #printDetail .bor {border-top: 1px solid;padding-top: 10px;}
              #printDetail .tablef .top .w50 {margin-left: 15px;} #printDetail .tablef .tac .w50 {margin-left: 5px;}`,
          });
        });
      });
    },
    openBG(e) {
      this.formFieldsBG.chid = "";
      this.formFieldsBG.id = "";
      this.modelBG = true;
      this.BGDETAIL = e;
      let parma = {
        page: 1,
        rows: 30,
        sort: "modifyDate",
        order: "id",
        wheres: "[]",
      };
      this.http.post("/api/CampsiteHouse/getPageData", parma).then((res) => {
        this.formRulesBG[0][0].data = res.rows.map((i) => {
          return {
            key: i.id,
            value: i.name,
          };
        });
      });
    },
    submitBG() {
      this.$refs.formRulBG.validate(() => {
        let params = {
          orderNumber: this.BGDETAIL.parentNumber,
          childOrderNumber: [this.BGDETAIL.orderNumber],
          oldchId: this.BGDETAIL.chid,
          oldId: this.BGDETAIL.id,
          ...this.formFieldsBG,
        };
        this.http
          .post("/api/CampHouseOrder/ChangeHouse", params)
          .then((res) => {
            this.modelBG = false;
            this.$Message.success(res.message);
            this.$store.getters.data().viewPageTest.refresh();
          });
      });
    },
    GetMerchantPayInfo(e) {
      let pay_code = this.getFormOptionYJ("pay_code");
      let parma = {
        unitId: e.unitId,
      };
      this.http
        .get("/api/CampHouseOrder/GetMerchantPayInfo", parma)
        .then((res) => {
          pay_code.data = res.data.map((i) => {
            return {
              key: i.code,
              value: i.name,
            };
          });
        });
    },
    // 入账
    openRZ(e) {
      this.modelRZ = true;
      this.RZDETAIL = e;
      this.getCampHousGoods();
      this.DepositGetPageData();
      this.GetMerchantPayInfo(e);
    },
    getCampHousGoods() {
      let p = new Promise((resolve, reject) => {
        let params = {
          page: 1,
          rows: 1000,
          sort: "createDate",
          order: "desc",
          wheres: `[]`,
        };
        this.http.post("/api/CampHouseGood/getPageData", params).then((res) => {
          this.goodList = res.rows;
          resolve(this.goodList);
        });
      });
      return p;
    },
    DepositGetPageData() {
      let params = {
        page: 1,
        rows: 1000,
        sort: "createDate",
        order: "desc",
        wheres: `[{\"name\":\"orderNumber\",\"value\":\"${this.RZDETAIL.orderNumber}\",\"displayType\":\"text\"}]`,
      };
      this.http
        .post("/api/CampHouseDeposit/getPageData", params)
        .then((res) => {
          this.orderTableData = res.rows;
          res.rows.forEach((i) => {
            i.hasChildren = true;
          });
        });
    },
    addYJ() {
      this.modelAddJZ = true;
      this.goodTitle = "新增商品";
      this.goodTableData = [
        {
          id: 1,
          goodId: "",
          goodNum: 1,
        },
      ];
      this.formFieldsYJ.authcode = "";
      this.getCampHousGoods();
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    editYJ() {
      if (this.multipleSelection.length == 1) {
        this.goodTitle = "编辑商品";
        this.modelAddJZ = true;
        this.getCampHousGoods().then((res) => {
          let para = {
            order: "desc",
            page: 1,
            rows: 1000,
            sort: "createDate",
            wheres: `[{"name":"depositId","value":"${this.multipleSelection[0].id}","displayType":"text"}]`,
          };
          this.http
            .post("/api/CampHouseDepositItem/GetPageData", para)
            .then((res) => {
              if (res.rows.length != 0) {
                res.rows.forEach((i) => {
                  i.goodNum = 1;
                });
                this.BildGoodList = JSON.parse(JSON.stringify(res.rows));
                this.goodTableData = this.delsameObjvalue(
                  res.rows,
                  "goodNum",
                  ["goodId"],
                  ["goodNum"]
                );
              }
            });
        });
      } else {
        this.$Message.error("只能选一个");
      }
    },
    addGoods() {
      let obj = {
        // id:
        //   this.goodTableData.length != 0
        //     ? Number(this.goodTableData[this.goodTableData.length - 1].id) + 1
        //     : 1,
        goodId: "",
        goodNum: 1,
      };
      this.goodTableData.push(obj);
    },
    delGoods(e) {
      if (this.goodTableData.length > 1) {
        this.goodTableData.forEach((i, ii, arr) => {
          if (i.id == e.id) {
            arr.splice(ii, 1);
          }
        });
      } else {
        this.$Message.error("至少保留一个商品");
      }
    },
    setShop(e) {
      e.goodNum = 1;
    },
    setGoodsNum() {
      this.goodTableData.forEach((j) => {
        this.goodList.forEach((i) => {
          if (i.id == j.goodId) {
            let num = 0;
            num += j.goodNum;
            if (num > i.saleStock) {
              this.$Message.error("商品库存不够,请重新输入数量");
              this.goodsStatus = false;
            } else {
              this.goodsStatus = true;
            }
          }
        });
      });
    },
    submitAddGoods() {
      this.getCampHousGoods().then((re) => {
        this.setGoodsNum();
        if (this.goodsStatus) {
          let detailData = [];
          if (this.goodTitle == "新增商品") {
            this.goodTableData.forEach((j) => {
              this.goodList.forEach((i) => {
                let obj = {};
                if (i.id == j.goodId) {
                  obj = {
                    goodId: i.id,
                    goodName: i.name,
                    paydepositPrice: i.paydepositPrice,
                    originalPrice: i.originalPrice,
                    deductionDepositPrice: 0,
                  };
                  for (let k = 0; k < j.goodNum; k++) {
                    detailData.push(obj);
                  }
                }
              });
            });
            let params = {
              mainData: {
                orderNumber: this.RZDETAIL.orderNumber,
                parentNumber: this.RZDETAIL.parentNumber,
                isPay: 0,
                isRefund: 0,
                isHouseDeposit: 1,
              },
              detailData: detailData,
              delKeys: null,
            };
            this.http.post("/api/CampHouseDeposit/Add", params).then((res) => {
              if (res.status) {
                this.modelAddJZ = false;
                this.DepositGetPageData();
              } else {
                this.$Message.error(res.message);
              }
            });
          } else {
            this.BildGoodList.forEach((i) => {
              i.goodNum = 1;
            });
            let A = this.delsameObjvalue(
              this.BildGoodList,
              "goodNum",
              ["goodId"],
              ["goodNum"]
            );
            let arrA = []; // -
            let arrB = []; // +
            // 减
            let goodIdA = A.filter(
              (i) => !this.goodTableData.map((j) => j.goodId).includes(i.goodId)
            );
            this.BildGoodList.forEach((i) => {
              goodIdA.forEach((j) => {
                if (i.goodId == j.goodId) {
                  arrA.push(i.id);
                }
              });
            });
            // 加
            let goodIdB = this.goodTableData
              .filter((i) => !A.map((j) => j.goodId).includes(i.goodId))
              .map((i) => i.goodId);
            this.goodTableData.forEach((j) => {
              if (goodIdB.includes(j.goodId)) {
                let obj = {
                  goodId: j.goodId,
                  deductionDepositPrice: 0,
                };
                for (let k = 0; k < j.goodNum; k++) {
                  arrB.push(obj);
                }
              }
            });

            A.forEach((i, ii, iii) => {
              this.goodTableData.forEach((j, jj, jjj) => {
                if (i.goodId == j.goodId) {
                  if (i.goodNum > j.goodNum) {
                    let c = i.goodNum - j.goodNum;
                    let n = this.BildGoodList.filter((m) => {
                      return m.goodId == i.goodId;
                    });
                    let v = n.map((l) => {
                      return l.id;
                    });
                    v.length = c;
                    arrA.push(...v);
                    let nx = n.filter((p) => {
                      return !v.includes(p.id);
                    });
                    arrB.push(...nx);
                  } else {
                    this.BildGoodList.forEach((p) => {
                      if (p.goodId == j.goodId) {
                        arrB.push(p);
                      }
                    });
                    let obj = {
                      goodId: j.goodId,
                      deductionDepositPrice: 0,
                    };
                    for (let k = 0; k < j.goodNum - i.goodNum; k++) {
                      arrB.push(obj);
                    }
                  }
                }
              });
            });
            arrB.forEach((i) => {
              this.goodList.forEach((j) => {
                if (i.goodId == j.id) {
                  i.paydepositPrice = j.paydepositPrice;
                  i.originalPrice = j.originalPrice;
                  i.goodName = j.name;
                }
              });
            });
            detailData.push(...arrB);
            let params = {
              mainData: {
                isPay: 0,
                isRefund: 0,
                isHouseDeposit: 1,
                id: this.multipleSelection[0].id,
              },
              detailData: detailData,
              delKeys: arrA ? arrA : null,
            };
            this.http
              .post("/api/CampHouseDeposit/update", params)
              .then((res) => {
                if (res.status) {
                  this.modelAddJZ = false;
                  this.DepositGetPageData();
                } else {
                  this.$Message.error(res.message);
                }
              });
          }
        }
      });
    },
    submitYJ() {
      let parma = {
        authcode: this.formFieldsYJ.authcode,
        pay_code: this.formFieldsYJ.pay_code,
        outTradeNo: this.outTradeNo,
        repeatPay: this.formFieldsYJ.isPay == 2 ? 1 : 0,
      };
      this.http
        .post("/api/CampHouseOrder/PayGoodDeposit", parma)
        .then((res) => {
          this.resultsOutTraeNo = res.results.outTradeNo;
          if (res.status) {
            this.modelYJ = false;
            this.$Message.success("入账成功");
            this.getCampHousGoods();
            this.DepositGetPageData();
          } else {
            if (res.data) {
              // 未知 1 失败 2
              if (res.data == 1) {
                this.orderTime = setInterval(() => {
                  this.DepositQuery();
                }, 2000);
                setTimeout(() => {
                  clearInterval(this.orderTime);
                }, 60 * 1000);
              }
            }
            this.$Message.error(res.message);
          }
          this.DepositGetPageData();
        });
    },
    payClick(e) {
      this.outTradeNo = e.outTradeNo;
      this.formFieldsYJ.yj = e.totalPrice;
      this.formFieldsYJ.isPay = e.isPay;
      this.$confirm("此订单是否需要折扣", "折扣", {
        distinguishCancelAndClose: false,
        confirmButtonText: "是",
        cancelButtonText: "否",
      })
        .then(() => {
          this.formFieldsZK.id = e.id;
          this.modelZK = true;
        })
        .catch((action) => {
          this.modelYJ = true;
        });
    },
    submitZK() {
      this.formFieldsZK.discount =
        this.formFieldsZK.discount == "" ? 0 : this.formFieldsZK.discount;
      this.formFieldsZK.depositDiscount =
        this.formFieldsZK.depositDiscount == ""
          ? 0
          : this.formFieldsZK.depositDiscount;
      let parma = {
        mainData: {
          ...this.formFieldsZK,
        },
        detailData: null,
        delKeys: null,
      };
      this.http.post("/api/CampHouseDeposit/Update", parma).then((res) => {
        if (res.status) {
          this.modelZK = false;
          this.modelYJ = true;
        } else {
          this.$Message.error(res.message);
        }
      });
    },
    DepositQuery() {
      let parma = {
        outTradeNo: this.resultsOutTraeNo,
      };
      this.http
        .post("/api/CampHouseOrder/DepositGoodQuery", parma)
        .then((res) => {
          if (res.status) {
            this.$Message.success("入账成功");
            this.modelYJ = false;
            this.getCampHousGoods();
            this.DepositGetPageData();
            clearInterval(this.orderTime);
          } else {
            this.$Message.error(res.message);
          }
        });
    },
    handleExpandChange(row, expandedRows) {
      if (expandedRows.length == 0) {
        this.expanRows = [];
      } else {
        this.expanRows = [];
        if (row.isHouseDeposit == 0) {
          this.goodListInfo = [
            {
              goodName: "房屋",
              originalPrice: "--",
              paydepositPrice: row.depositPrice,
            },
          ];
          this.expanRows.push(row.id);
        } else {
          let parma = {
            page: 1,
            rows: 1000,
            sort: "createDate",
            order: "desc",
            wheres: `[{\"name\":\"depositId\",\"value\":\"${row.id}\",\"displayType\":\"text\"}]`,
          };
          this.http
            .post("/api/CampHouseDepositItem/GetPageData", parma)
            .then((res) => {
              if (res.rows.length != 0) {
                this.goodListInfo = res.rows;
                if (this.expanRows.includes(row.id)) {
                  this.expanRows = this.expanRows.filter(
                    (val) => val !== row.id
                  );
                } else {
                  if (this.expanRows.length != 0) {
                    this.expanRows.splice(0, this.expanRows.length);
                    this.expanRows.push(row.id);
                  } else {
                    this.expanRows.push(row.id);
                  }
                }
              } else {
                this.$Message.error(res.message);
              }
            });
        }
      }
    },
    handleExpandChange2(row, expandedRows) {
      if (expandedRows.length == 0) {
        this.expandRows = [];
      } else {
        this.expandRows = [];
        this.tkRow = row;
        if (row.isHouseDeposit == 0) {
          this.goodListInfo = [
            {
              goodName: "房屋",
              originalPrice: "--",
              paydepositPrice: row.depositPrice,
            },
          ];
          this.expandRows.push(row.id);
        } else {
          if (row.campHouseDepositItems.length != 0) {
            this.goodListInfo = row.campHouseDepositItems;
            if (this.expandRows.includes(row.id)) {
              this.expandRows = this.expandRows.filter((val) => val !== row.id);
            } else {
              if (this.expandRows.length != 0) {
                this.expandRows.splice(0, this.expandRows.length);
                this.expandRows.push(row.id);
              } else {
                this.expandRows.push(row.id);
              }
            }
          } else {
            this.$Message.error(res.message);
          }
        }
      }
    },
    // 结账
    openJZ(e) {
      this.modelJZ = true;
      this.RZDETAIL = e;
      let params = {
        orderNumber: this.RZDETAIL.orderNumber,
      };
      this.http
        .get("/api/CampHouseDeposit/GetDataDeposi", params)
        .then((res) => {
          res.rows.forEach((i) => {
            i.hasChildren = true;
          });
          this.goodsOrderTableData = res.rows;
        });
    },
    submitJZ() {
      let parma = {
        chid: this.RZDETAIL.chid,
        id: this.RZDETAIL.id,
        childOrderNumber: [this.goodsOrderTableData[0].orderNumber],
      };
      this.http.post("/api/CampHouseOrder/DepositRefund", parma).then((res) => {
        if (res.status) {
          this.$Message.success("退款成功");
          this.modelJZ = false;
          this.$store.getters.data().viewPageTest.refresh();
          this.billPrintClick(this.RZDETAIL);
        } else {
          this.$Message.error(res.message);
        }
      });
    },
    submitKYJ(e) {
      let parma = {
        mainData: {
          ...e,
        },
        detailData: e.campHouseDepositItems,
        delKeys: null,
      };
      this.http.post("/api/CampHouseDeposit/update", parma).then((res) => {});
    },
  },
};
</script>
<style scoped lang="less">
#printDetail {
  height: 100px;
  font-size: 6px;
  h3 {
    margin: 10px 0;
  }
  .zfnr {
    text-align: right;
    margin-top: 20px;
    .payStatus {
      margin-top: 10px;
      text-align: left;

      .tw {
        text-align: right;
        .zj {
          display: inline-block;
          width: 80px;
          text-align: right;
        }
      }
    }
  }
  .bor {
    border-top: 1px solid;
    padding-top: 10px;
  }
  .tablef {
    .top {
      .w50 {
        margin-left: 15px;
      }
    }
    .tac {
      .w50 {
        margin-left: 5px;
      }
    }
  }
}

.goods {
  display: flex;
  .goodsr {
    width: 150px;
    margin-top: 6px;
    margin-left: 10px;
  }
}
.Vhennys {
  position: relative;
  left: 50%;
  margin: 10px;
  transform: translateX(-50%);
}
.bot10 {
  margin-bottom: 10px;
}
/deep/ .el-table td,
.el-table th.is-leaf {
  padding: 0px !important;
  background-color: #f8f8f9 !important;
  font-size: 13px;
  height: 41px;
  color: #616161;
}
/deep/ .el-table .el-table__header .is-leaf {
  padding: 0px !important;
  background-color: #f8f8f9 !important;
  font-size: 13px;
  height: 41px;
  color: #616161;
}
</style>